package cn.kgc.service.impl;

import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;

import cn.kgc.mapper.JobpostingMapper;
import cn.kgc.pojo.Jobposting;
import cn.kgc.service.JobpostingService;
import cn.kgc.util.Page;
import cn.kgc.util.PageData;
import com.alibaba.dubbo.config.annotation.Service;

/**
* 描述： 服务实现层接口
* @author 
* @date 2018/03/05
*/
@Service
public class JobpostingServiceImpl implements JobpostingService {
	@Resource
	private JobpostingMapper jobpostingMapper;
 	
 	/**
    * 描述：根据Id获取Jobposting对象
    * @param id
    */
    public Jobposting findById(Integer id){
    	return jobpostingMapper.findById(id);
    }

	/**
    * 描述：获取所有的Jobposting对象
    */
    public List<Jobposting> findAll(){
    	return jobpostingMapper.findAll();
    }

	/**
    * 描述：新增保存Jobposting对象
    */
    public int save(Jobposting jobposting){
    	return  jobpostingMapper.save(jobposting);
    }

	/**
    * 描述：根据Id删除Jobposting对象
    * @param id
    */
    public int delete(Serializable id){
    	return  jobpostingMapper.delete(id);
    }
	
	/**
    * 描述：更新Jobposting对象
    */
    public int update(Jobposting jobposting){
    	return  jobpostingMapper.update(jobposting);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Jobposting> query(Object params){
    	return  jobpostingMapper.query(params);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(Object params, Page page){
    	int totalCount = jobpostingMapper.getCount(params);
    	int totalPageCount = (totalCount-1)/page.getSize()+1;
    	if(page.getPageIndex()<1){
    		page.setPageIndex(1);
    	}else if(page.getPageIndex()>totalPageCount){
    		page.setPageIndex(totalPageCount);
    	}
    	page.setTotalCount(totalCount);
    	page.setTotalPage(totalPageCount);
    	int firstRow=(page.getPageIndex()-1)*page.getSize();
    	List list = jobpostingMapper.queryByPage(params,firstRow,page.getSize());
    	page.setList(list);
    	return page;
    	
    }

	@Override
	public Integer getCount() {
		return null;
	}

	@Override
	public List<Jobposting> getJbposting(Integer userId) {
		return null;
	}

	@Override
	public List<Jobposting> getHasJbposting(Integer userId) {
		return null;
	}

	@Override
	public List<Jobposting> getNoJbposting(Integer userId) {
		return null;
	}

	@Override
	public List<Jobposting> getJbpostingXiajia(Integer userId) {
		return null;
	}

	@Override
	public Integer updateJobposting(Integer resumeId, Integer state) {
		return null;
	}

	@Override
	public List<Jobposting> selectJobposting(Integer positionId, String workCity, String monthly) {
		return null;
	}

	@Override
	public List<Jobposting> getJobpostingByPosition(String position) {
		return jobpostingMapper.getJobpostingByPosition(position);
	}

	@Override
	public List<Jobposting> getAllJobposting() {
		return jobpostingMapper.getAllJobposting();
	}

	@Override
	public PageData queryByPosition(String position,Integer pageIndex,Integer size) {
    	PageData pageData=new PageData();
    	pageData.setPageIndex(pageIndex);
    	pageData.setSize(size);
		int totalCount = jobpostingMapper.getCountByPosition(position);
		pageData.setTotalCount(totalCount);
		int index=(pageIndex-1)*size;
		List list = jobpostingMapper.queryByPosition(position,index,size);
		pageData.setList(list);
		return pageData;
	}

	@Override
	public int getCountByPosition(String position) {
		return jobpostingMapper.getCountByPosition(position);
	}

	@Override
	public PageData queryByCategory(String category, Integer pageIndex2, Integer size2) {
		PageData pageData=new PageData();
		pageData.setPageIndex(pageIndex2);
		pageData.setSize(size2);
		int totalCount = jobpostingMapper.getCountByCategory(category);
		pageData.setTotalCount(totalCount);
		int index=(pageIndex2-1)*size2;
		List list = jobpostingMapper.queryByCategory(category,index,size2);
		pageData.setList(list);
		return pageData;
	}

	@Override
	public int getCountByCategory(String category) {
		return jobpostingMapper.getCountByCategory(category);
	}


}
